package com.example.artwindow.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.example.artwindow.constants.AutoFillConstants;
import com.example.artwindow.tool.TheadLocalTool;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AutoFillMetaObjectHandler implements MetaObjectHandler {
	@Override
	public void insertFill(MetaObject metaObject) {
		this.setFieldValByName(AutoFillConstants.SET_CREAT_USER, TheadLocalTool.getCurrentId(),metaObject);
		this.setFieldValByName(AutoFillConstants.SET_CREAT_TIME, System.currentTimeMillis(),metaObject);
		this.setFieldValByName(AutoFillConstants.SET_UPDATE_USER, TheadLocalTool.getCurrentId(),metaObject);
		this.setFieldValByName(AutoFillConstants.SET_UPDATE_TIME, System.currentTimeMillis(),metaObject);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		this.setFieldValByName(AutoFillConstants.SET_UPDATE_USER, TheadLocalTool.getCurrentId(),metaObject);
		this.setFieldValByName(AutoFillConstants.SET_UPDATE_TIME, System.currentTimeMillis(),metaObject);
	}
}
